<?php
	$layout = $this->cmsSearch('', '100%'); 
	echo $layout;
	$layout = $this->cmsSubmenu(); 
	echo $layout;
	
	// Chi tiết tin
	$info = $this->itemsViewOghTinTro;
	$tieu_de 	= $info->tieu_de;
	$ngay_dang 	= $info->ngay_dang;
	$datetime 	= explode(" ", $ngay_dang);
	$dia_chi 	= $info->dia_chi;
	$thanh_pho 	= $info->getThanhPhoObj()->ten;
	$quan_huyen = $info->getQuanHuyenObj()->ten;
	$luot_xem 	= $info->luot_xem;
	$loai_phong = $info->getLoaiPhongObj()->ten;
	$so_nguoi_o = $info->so_nguoi_o;
	$gia_phong 	= number_format($info->gia_o_ghep, 3, ",", ",") . ' VNĐ';
	if ($info->gia_o_ghep == null || $info->gia_o_ghep == 0)
		$gia_phong = 'Thỏa thuận';
	$dien_tich 	= $info->dien_tich_phong;
	$mo_ta 		= $info->mo_ta;
	$nguoi_lien_he = $info->nguoi_lien_he;
	$so_dien_thoai = $info->so_dien_thoai;
	$nguoi_dang = $info->getNguoiDangObj();
	$email = $nguoi_dang->email;
	
	$frm_sendmailfriend = $this->form_sendmail;
	$frm_sendmail = $this->form_sendmailtoposter;
?>
<div id="wrapcontent">
	<div id="sidebar1">
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_hot.gif") . '" />';
			$block = $this->cmsBlock('Phòng trọ', $img, $this->itemsHotPtrTinTro); 
			echo $block;
		?>
		<!-- Begin Block hỗ trợ trực tuyến -->
		<?php 
			$block = $this->cmsBlock('Hỗ trợ trực tuyến', '', $this->thong_tin_cty, 3); 
			echo $block;
		?>
		<!-- End Block hỗ trợ trực tuyến -->
		<!-- Begin Block thống kê truy cập -->
		<?php 
			$block = $this->cmsBlock('Thống kê truy cập', '', 'info', 4); 
			echo $block;
		?>
		<!-- End Block thống kê truy cập -->
		<br class="clear" />
	</div>
	<div id="sidebar2">
		<div class="block">
			<div class="title">
				<span>Mạng xã hội</span>
			</div>
			<div class="content">
				<div class="follow">
					<div class="addthis_toolbox addthis_32x32_style addthis_vertical_style">
						<a class="addthis_button_facebook_follow" addthis:userid="kenhnhatro.vn"></a>
						<a class="addthis_button_twitter_follow" addthis:userid="kenh_nhatro"></a>
					</div>
				</div>
			</div>
			<br class="clear" />
		</div>
		<?php
			$img = '<img src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/icon_new.gif") . '" />';
			$block = $this->cmsBlock('Tin rao mới', $img, $this->itemsNewPtrTinTro); 
			echo $block;
			$img = '<img class="icon" src="' . $this->baseUrl(PUBLIC_PATH . "/img/icon/highlights.png") . '" />';
			$block = $this->cmsBlock('Tin tức nổi bật', $img, $this->itemsHotTinTuc, 2);
			echo $block;
		?>
	</div>
	<div id="primary">
		<div class="block">
			<div class="title">
				<div class="icon-arrow"></div>
				<span>Phòng cho thuê</span>
			</div>
			<div class="content">
				<p class="tieu-de"><?php echo $tieu_de; ?></p>
				<div class="meta">
					<span class="datetime"><?php echo $datetime[1]; ?> <font class="date"><?php echo $datetime[0]; ?></font></span>
					Vị trí: <span class="address"><?php echo $thanh_pho . ', ' . $quan_huyen; ?></span>
					<span><b><?php echo $luot_xem; ?></b> Lượt xem</span>
					<!-- AddThis Button BEGIN -->
					<div class="addthis_toolbox addthis_default_style add-button">
						<a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>
						<a class="addthis_button_tweet"></a>
						<a class="addthis_button_pinterest_pinit"></a>
						<a class="addthis_counter addthis_pill_style"></a>
					</div>
					<!-- AddThis Button END -->
				</div>
				<div class="view-info">
					<table width="100%">
						<tr>
							<th><label>Loại phòng trọ: </label></th>
							<td><?php echo $loai_phong; ?></td>
						</tr>
						<tr>
							<th><label>Số người ở: </label></th>
							<td><?php echo $so_nguoi_o; ?></td>
						</tr>
						<tr>
							<th><label>Giá ở ghép: </label></th>
							<td><span><?php echo $gia_phong; ?></span></td>
						</tr>
						<tr>
							<th><label>Diện tích: </label></th>
							<td><?php echo $dien_tich; ?> m<sup>2</sup></td>
						</tr>
						<tr>
							<th><label>Địa chỉ: </label></th>
							<td><?php echo $dia_chi . ' - ' . $quan_huyen . ' - ' . $thanh_pho; ?></td>
						</tr>
					</table>
					<div class="description"><?php echo $mo_ta; ?></div>
					<div class="toolbar">
						<ul>
							<li><a class="back" href="#" onclick="history.go(-1)">Quay lại</a></li>
							<li><a class="forward" href="#sendFriendModal" data-toggle="modal">Gửi cho bạn bè</a></li>
							<li><a class="spam" class="confirm-dialog" onclick="<?php echo 'return confirmDialog(this, \'/oghtinrao/baoxau/id/' . $this->arrParam['id'] . '\');'; ?>" href="#">Báo xấu</a></li>
						</ul>
					</div>
					<div class="line-break"></div>
					<p class="head-contact">Thông tin liên hệ</p>
					<div class="contact-info">
						<table>
							<tr>
								<th><label>Người liên hệ: </label></th>
								<td><?php echo $nguoi_lien_he; ?></td>
							</tr>
							<tr>
								<th><label>Điện thoại: </label></th>
								<td><?php echo $so_dien_thoai; ?></td>
							</tr>
							<tr>
								<th><label>Email: </label></th>
								<td>
									<?php echo $email; ?><br />
									<a class="sendemail" href="#sendMailModal" data-toggle="modal">Gửi cho người đăng</a>
								</td>
							</tr>
						</table>
					</div>
				</div>
				<div class="comment">
					<p>Bình Luận</p>
					<div class="frm-comment">
						<?php echo $this->disqus('kenhnhatro'); ?>
					</div>
				</div>
				<br class="clear" />
			</div>
			<br class="clear" />
		</div>
	</div>
	<div class="dialog" id="question">
		<img src="<?php echo $this->baseUrl(PUBLIC_PATH . '/img/question.png'); ?>" alt="question" />
		<p>Bạn có chắc muốn báo xấu tin này không?</p>
	</div>
	<!-- SEND MAIL FOR FRIEND MODAL -->
	<div id="sendFriendModal" class="modal hide fade" tabindex="-1"
		role="dialog" aria-labelledby="sendFriendModalLabel" aria-hidden="true">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-hidden="true">×</button>
			<h3 id="sendFriendModalLabel">Gửi cho bạn bè tin này</h3>
		</div>
		<div class="modal-body">
			<div id="sendfriendalert" class="alert"></div>
			<form class="form-horizontal">
				<?php echo $frm_sendmailfriend->link_bai_viet;?>
				<div class="control-group">
					<label class="control-label" for="ten_nguoi_gui">Tên của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->ten_nguoi_gui;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="email_from">Email của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->email_from;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="email_to">Gửi đến (To)</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->email_to;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="tieu_de">Tiêu đề (Subject)</label>
					<div class="controls">
					<?php echo $frm_sendmailfriend->tieu_de;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="thong_diep">Thông điệp (Message)</label>
					<div class="controls">
						<?php echo $frm_sendmailfriend->thong_diep;?>
					</div>
				</div>
			</form>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" aria-hidden="true">Bỏ qua</button>
			<button id="btnSendFriend" class="btn btn-primary">Gửi</button>
		</div>
	</div>
	<!-- SEND MAIL CHO NGUOI DANG MODAL -->
	<div id="sendMailModal" class="modal hide fade" tabindex="-1"
		role="dialog" aria-labelledby="sendMailModalLabel" aria-hidden="true">
		<div class="modal-header">
			<button type="button" class="close" data-dismiss="modal"
				aria-hidden="true">×</button>
			<h3 id="sendMailModalLabel">Gửi cho người đăng tin</h3>
		</div>
		<div class="modal-body">
			<?php if ($this->state_login) {?>
			<div id="sendmailalert" class="alert"></div>
			<form class="form-horizontal">
				<?php 
					echo $frm_sendmail->loai_bai_dang->setValue('oghtinrao');
					echo $frm_sendmail->id_bai_dang->setValue($this->arrParam['id']);
					echo $frm_sendmail->id_nguoi_dang->setValue($nguoi_dang->id);
					echo $frm_sendmail->email_nguoi_dang->setValue($nguoi_dang->email);
				?>
				<div class="control-group">
					<label class="control-label" for="nguoi_gui">Tên của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmail->nguoi_gui;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="email_nguoi_gui">Email của bạn</label>
					<div class="controls">
					<?php echo $frm_sendmail->email_nguoi_gui;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="subject">Tiêu đề (Subject)</label>
					<div class="controls">
					<?php echo $frm_sendmail->subject;?>
					</div>
				</div>
				<div class="control-group">
					<label class="control-label" for="message">Thông điệp (Message)</label>
					<div class="controls">
						<?php echo $frm_sendmail->message;?>
					</div>
				</div>
			</form>
			<?php } else {?>
			<p class="errors">Phải đăng nhập mới có thể thực hiện thao tác này.</p>
			<?php } ?>
		</div>
		<div class="modal-footer">
			<button class="btn" data-dismiss="modal" aria-hidden="true">Bỏ qua</button>
			<?php if ($this->state_login) {?>
			<button id="btnSendMail" class="btn btn-primary">Gửi</button>
			<?php } else { ?>
			<a class="btn btn-primary" onclick="loginbtnClick()" data-dismiss="modal">Đăng nhập</a>
			<?php } ?>
		</div>
	</div>
	<script type="text/javascript">
		//Catch keydown event of the enter key
		$('#sendFriendModal, #sendMailModal').keydown(function (e){
			if(e.keyCode == 13){
				sendForFriendProcess(e);
			}
		});
		//Catch click event of the forward button
		$('#btnSendFriend').click(function(e) {
			sendForFriendProcess(e);
		});
		//Catch click event of the send mail button
		$('#btnSendMail').click(function(e) {
			sendMailProcess(e);
		});
		
		$('#forward').click(function() {
			$('#sendfriendalert').hide();
		});
		
		$('#sendmail').click(function() {
			$('#sendmailalert').hide();
		});
		
		//Show the modal event processing
		$('#sendFriendModal, #sendMailModal').on('show', function () {
			$(this).find('.alert').hide();
			$(this).find("input").each(function() {
				var inputid = $(this).attr('id');
				$("#"+inputid).parent().find('.errors').remove();
				$("#"+inputid+'[type="text"]').val("");
		    });
			$(this).find("textarea").each(function() {
				var inputid = $(this).attr('id');
				$("#"+inputid).val("");
		    });
		});
		
		$(function(){
			$('#sendFriendModal').find("input").each(function() {
		        var inputid = $(this).attr('id');
		        $("#"+inputid).blur(function() {
		        	if(doValidation('sendFriendModal', inputid,'/ajax/validateforward', null))
		        		$("#btnSendFriend").removeAttr("disabled");
		        	else
		        		$("#btnSendFriend").attr("disabled", "disabled");	
		        });
		    });
		});
		
		$(function(){
			$('#sendMailModal').find("input").each(function() {
		        var inputid = $(this).attr('id');
		        $("#"+inputid).blur(function() {
		        	if(doValidation('sendMailModal', inputid, '/ajax/validatesendmail', null))
		        		$("#btnSendMail").removeAttr("disabled");
		        	else
		        		$("#btnSendMail").attr("disabled", "disabled");	
		        });
		    });
		});
		//Process forward function
		function sendForFriendProcess(event) {
			var url = '/ajax/sendforfriend';
			var $this = $(this);
			var postData = $("#sendFriendModal form").serializeObject();
			postData.format = "json";
			var isValid = true;
			$('#sendFriendModal').find("input").each(function() {
				var inputid = $(this).attr('id');
				isValid = isValid&&doValidation('sendFriendModal', inputid, '/ajax/validateforward', 'validate');
		    });
			if(isValid){
				$("#btnSendFriend").attr("disabled", "disabled");
				$.ajax({
		            type: 'POST',
		            url: url,
		            async: true,
		            cache: true,
		            data: postData,
		            dataType: postData.format,
		            success: function(data){
		            	if(data.result) {
	                		$('#sendfriendalert').html(data.message);
	                		$('#sendfriendalert').show();
		            		setTimeout(function() {
								$('#sendFriendModal').modal('hide'); 
							}, 1000);
		            	} else {
		            		if(data.message){
		                		$('#sendfriendalert').html(data.message);
		                		$('#sendfriendalert').show();
		                    }
		                }
		            }
		        });
				$("#btnSendFriend").removeAttr("disabled");
			}
		}
		//Process send mail function
		function sendMailProcess(event) {
			var url = '/ajax/sendmail';
			var $this = $(this);
			var postData = $("#sendMailModal form").serializeObject();
			postData.format = "json";
			var isValid = true;
			$('#sendMailModal').find("input").each(function() {
				var inputid = $(this).attr('id');
				isValid = isValid&&doValidation('sendMailModal', inputid, '/ajax/validatesendmail', 'validate');
		    });
			if(isValid){
				$("#btnSendMail").attr("disabled", "disabled");
				$.ajax({
		            type: 'POST',
		            url: url,
		            async: true,
		            cache: true,
		            data: postData,
		            dataType: postData.format,
		            success: function(data){
		            	if(data.result) {
	                		$('#sendmailalert').html(data.message);
	                		$('#sendmailalert').show();
		            		setTimeout(function() {
								$('#sendMailModal').modal('hide'); 
							}, 1000);
		            	} else {
		            		if(data.message){
		                		$('#sendmailalert').html(data.message);
		                		$('#sendmailalert').show();
		                    }
		                }
		            }
		        });
				$("#btnSendMail").removeAttr("disabled");
			}
		}
	</script>
   	<div class="clear"></div>
</div>